/*
 * Copyright (c) 2013 Andaily Information Technology Co. Ltd
 * www.andaily.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Andaily Information Technology Co. Ltd ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement you
 * entered into with Andaily Information Technology Co. Ltd.
 */
package top.suven.http.oauth.validator;

import org.apache.oltu.oauth2.as.request.AbstractOAuthTokenRequest;
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Set;

/**
 * 2018-08-01
 * <p/>
 *  AbstractOauthTokenValidator
 *  *  客户端	客户详细资料 抽像模块类，用于公共验证和获取客户用户的信息；
 *  * 将通用的行为(方法) 位于此
 *  4.客户端模式（client credentials）
 * grant_type=client_credentials
 * @author suven.wang client_credentials
 */
/**
 * /oauth/token?client_id=credentials-client&client_secret=credentials-secret&grant_type=client_credentials&scope=read write
 **/
//ClientCredential client_credential
public class GrantTypeClientCredentialValidator extends AbstractOauthGrantTypeValidator {

    private static final Logger logger = LoggerFactory.getLogger(GrantTypeClientCredentialValidator.class);


    public GrantTypeClientCredentialValidator(AbstractOAuthTokenRequest oauthRequest) {
        super(oauthRequest);
    }

    /*
    * /oauth/token?client_id=credentials-client&client_secret=credentials-secret&grant_type=client_credentials&scope=read write
    * */
    @Override
    protected boolean validateSelf() throws OAuthSystemException {

        // 前4点 基于token 验证于AbstractOauthTokenValidator 抽象
        if(!this.validateGrantType()){
            return false;
        }

        //5. validate scope
        final Set<String> scopes = oauthRequest.getScopes();
//        if (scopes.isEmpty() || excludeScopes(scopes, clientDetails)) {
//            return invalidScopeResponse();
//        }

        return true;
    }


}
